package idv.jieh.language;

import java.io.*;

public class LanguageParser extends idv.jieh.commons.comm.BasicClass{

  public static String parse(String str){
    str = idv.jieh.commons.util.DataAnalysis.trimNull(str);
    StringBuffer r = new StringBuffer();

    char[] chs = str.toCharArray();
    for(int i=0, l=chs.length; i<l; i++){
      int n = (int)chs[i];
      if(n < 128){
        r.append(chs[i]);
      }else{
        r.append(java.lang.Character.forDigit(92, 10));
        r.append("u");
        r.append(Integer.toHexString(n));
      }
    }

    return r.toString();
  }

  public static void main(String[] args) throws Exception{

//    idv.jieh.commons.io.OpenFiles of = new idv.jieh.commons.io.OpenFiles();
//    idv.jieh.commons.util.ConfigFile cf = new idv.jieh.commons.util.ConfigFile("D:/project/delta/mmiap/mmiapc/defaultroot/WEB-INF/classes", "ApplicationResources_zh_TW.txt");
//    of.load("D:/project/delta/mmiap/mmiapc/defaultroot/WEB-INF/classes", "ApplicationResources_zh_TW.properties");
//    of.open(0);
//    int i = 10;
//    while(of.ready()){
//      cf.put(String.valueOf(i), of.readLine());
//      i++;
//    }
//    cf.store();


    String s = null;
    System.out.println(java.lang.Character.forDigit(92, 10));

    s = "今回\u306F前回\u306B\u3072\u304D\u3064\u3065\u304D藤子\u30FBＦ\u30FB不二雄先生\u306E";
    System.out.println(s + " = " + parse(s));
    s = "到第 ";
    System.out.println(s + " = " + parse(s));
    s = "\u62A5 + ABC";
    System.out.println(s + " = " + parse(s));

    String r = null;
    try {
      r = new String(parse(s).getBytes("utf-8"));
    } catch (UnsupportedEncodingException ex) {
    }
    System.out.println(r);

    String s2 = "\\";
    System.out.println(s2.toCharArray().length);
    StringBuffer t = new StringBuffer(s2.toCharArray()[0]);
    t.append(s2.toCharArray()[0]);
    System.out.println(t);

  }

}// end class LanguageParser
